Skip to content

Conversation

@nevertrimnuts
Copy link

Im not sure whether something like this can or should be included in the core math library (or perhaps there's another better place to put it), but for me, and I expect for others as well following popular vulkan guides such as vkguide, it would be nice to have at least one note like this that fixes a bug like this, if only at least to advertise that the odin glsl math library is not a drop-in replacement for glm.

Also note: this is the first instance of a math bug happening because of a discrepancy between vkguide's math library of choice (glm) and the odin glsl library.

@JesseRMeyer
Copy link

GLM can be configured to support Vulkan's coordinate system, which is incompatible with OpenGL's. I'm not sure where in vkguide this is being done, as it's not mentioned anywhere explicitly. I think this is the source of the confusion.

https://community.khronos.org/t/confused-when-using-glm-for-projection/108548/2

Our GLSL compatibility assumes OpenGL, not Vulkan. I'm in favor of supplying a vulkan compatible perspective transform, but the note referring to vkguide isn't appropriate in core.

@nevertrimnuts
Copy link
Author

@JesseRMeyer where would be the best place to put something like a vulkan compatible perspective transform function? If I made a directory + file "core:math/linalg/vulkan/linalg_vulkan.odin" and started work on implementing vulkan-compatible math functions, would that be welcome?

GLM can be configured to support Vulkan's coordinate system, which is incompatible with OpenGL's. I'm not sure where in vkguide this is being done, as it's not mentioned anywhere explicitly.

The only way vkguide influences the compilation of glm is by defining the macro #GLM_FORCE_DEPTH_ZERO_TO_ONE, which ends up compiling this code in glm:

#ifdef GLM_FORCE_DEPTH_ZERO_TO_ONE
#	ifdef GLM_FORCE_LEFT_HANDED
#		define GLM_CONFIG_CLIP_CONTROL GLM_CLIP_CONTROL_LH_ZO
#	else
#		define GLM_CONFIG_CLIP_CONTROL GLM_CLIP_CONTROL_RH_ZO
#	endif
#else
#	ifdef GLM_FORCE_LEFT_HANDED
#		define GLM_CONFIG_CLIP_CONTROL GLM_CLIP_CONTROL_LH_NO
#	else
#		define GLM_CONFIG_CLIP_CONTROL GLM_CLIP_CONTROL_RH_NO
#	endif
#endif

which ends up compiling this function for perspective projection.

@nevertrimnuts nevertrimnuts closed this by deleting the head repository May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants